<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java"  contentType="text/html;charset=utf-8"%>
<%@ page import="com.qipay.baas.model.User" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.qipay.baas.model.CpAccountTradlog" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.admin.tags.PageModel" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="com.qipay.sp.SpUserService" %>
<%@ page import="com.qipay.core.utils.SpringContextUtil" %>
<%@ page import="com.qipay.core.entity.ValueObject" %>
<%@ page import="com.qipay.admin.sp.vo.SpUserDTO" %>
<%@ page import="com.qipay.core.help.BeanHelper" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.qipay.baas.model.SpUser" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <%
        User user = (User) session.getAttribute("user");
        int level = 0;
        String userName="游客";
        if (null != user) {
            userName = user.getName();
            level = user.getLevel();
        }
        List<SpUserDTO> spUserDTOS = null;
    %>
   <%-- <%if(level >= UserLevel.ADMIN_SON.getCode()){
        SpUserService spUserService = (SpUserService) SpringContextUtil.getBean(SpUserService.class);
        //取出供号商字典
        List<ValueObject> query = spUserService.query();
        spUserDTOS = BeanHelper.valueObjectToBean(query, SpUserDTO.class);
    %>
        <jsp:include page="add_spuser_order.jsp" flush="true">
            <jsp:param name="spUserDTOS" value="<%=JSONObject.toJSONString(spUserDTOS)%>"/>
        </jsp:include>
    <%}%>--%>

    <title><%= userName%>，祝您工作愉快！</title>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/square/blue.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/datetimepicker.css">
</head>
<body class="devpreview hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <div class="content-wrapper">
        <!-- Main content -->
        <%/*此为4方，所以一下功能暂时去掉*/
//            if(level > UserLevel.AGENT.getCode()){
              if(level > 100000){
        %>
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box border" >
                        <div style="position: relative;">
                            <h4 style="display: inline-block">充值记录</h4>
                            <%if(level >= UserLevel.ADMIN_SON.getCode()){%>
                            <button type="button" class="btn btn-success btn-sm borderNone"
                                    data-toggle="modal" id="addChongzhiModalId"
                                    data-target="#addChongzhiModal" style="position: relative;bottom: 4px;left: 15px;">
                                添加订单
                            </button>
                            <%}%>
                            <%if(level == UserLevel.ADMIN_Hao.getCode()){
                                SpUser spUser = (SpUser) request.getAttribute("spUser");
                                Integer accountMoney = (Integer) request.getAttribute("accountMoney");
                            %>
                            <div style="position: relative;bottom: 1px;display: inline-block">
                                <b style="font-size: 16px;padding-left: 1.6rem;">(费率：<%= SiteHelper.formatPercentage(spUser.getFeeRate())%>&ensp;&ensp;&ensp;&ensp;余额：
                                    <span style="color: red;font-size: 20px;">￥
                                        <%=SiteHelper.formatMoney(accountMoney, 100.0)%></span>)</b>
                            </div>
                            <%}%>
                        </div>
                        <%
                            Map<String, String> params = (Map<String, String>) request.getAttribute("params");
                        %>
                        <div id="searchForm">
                            <form  action="/index" >
                                <%if(level > UserLevel.ADMIN_Hao.getCode()){%>
                                    <div class="new-group" >
                                    <label for="spUserId">所属码商：</label>
                                    <select id="spUserId" name="spUserId">
                                        <option value="">所有</option>
                                        <% for (SpUserDTO s : spUserDTOS) {%>
                                        <option value="<%=s.getId()%>" ><%= s.getSpUserName()%>
                                                <%}%>
                                    </select>
                                </div>
                                <%}%>
                                <div class="new-group date form_datetime">
                                    <label for="from">开始日期：</label>
                                    <input type="text" id="from" name="from" readonly
                                           value="<%= params.containsKey("from") ?params.get("from"):""%>" data-date-format="yyyy-mm-dd hh:ii">
                                </div>
                                <div class="new-group date form_datetime">
                                    <label for="to">结束日期：</label>
                                    <input type="text" id="to" name="to" readonly
                                           value="<%= params.containsKey("to") ?params.get("to"):""%>" data-date-format="yyyy-mm-dd hh:ii">
                                </div>
                                <div class="button-group">
                                    <button type=" submit" class="btn btn-primary btn-sm borderNone"
                                            id="btnSearch" >查询</button>
                                </div>
                            </form>
                            <div style="clear: both;"></div>
                        </div>
                        <!-- /.box-header -->
                        <div class="tableContent">
                            <table class="table table-bped table-hover">
                                <thead>
                                <tr>
                                    <th width="3%">ID</th>
                                    <th width="5%">订单类型</th>
                                    <th width="5%">金额</th>
                                    <th width="5%">码商</th>
                                    <th width="10%">下单时间</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<CpAccountTradlog> articles = (List<CpAccountTradlog>) request.getAttribute("lst");
                                    PageModel pager = (PageModel) request.getAttribute("page");
                                    CpAccountTradlog tongji = (CpAccountTradlog) request.getAttribute("total");
                                    String query = pageContext.getRequest().getServletContext().getContextPath() + "/index" + pager.getUrl();
                                    query = StringUtils.replace(query, "s=null", "s=");
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<CpAccountTradlog> iter = articles.iterator();
                                        CpAccountTradlog cat = null;
                                        while (iter.hasNext()) {
                                            cat = iter.next();
                                %>
                                <tr>
                                    <td><%=cat.getId()%></td>
                                    <td>充值</td>
                                    <td><%=SiteHelper.formatMoney(cat.getAmount(), 100.0)%></td>
                                    <td>
                                        <%= cat.getCpId()%>--
                                        <%= cat.getRemark()%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getDefaultTimeFormat(cat.getCreateTime())%>
                                    </td>
                                </tr>
                                <%}} else {%>
                                <tr>
                                    <td colspan="5">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <p>
                                充值总数 :<%=SiteHelper.formatMoney(tongji.getAmount(), 100.0)%>&nbsp;&nbsp;
                                总笔数：<%= pager.getTotal()%>
                            </p>
                            <div class="col-sm-10" >
                                <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate" >
                                    <page:page totalSum="<%= pager.getTotal()%>"
                                               url="<%= query%>"
                                               pageNo="<%= pager.getPage()%>"
                                               pageSize="<%= pager.getPageSize()%>"></page:page>
                                </div>
                            </div>
                            <div style="clear: both"></div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div></div>
            <!-- /.row -->
        </section>
        <%}else{%>
        <section class="content">
            <div class="box border" >
                <h2>welcome</h2>
            </div>
        </section>

        <%}%>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <%--<jsp:include page="foot.jsp"></jsp:include>--%>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datetimepicker.min.js"></script>
<script language="JavaScript">
    // $('#addChongzhiModalId').click();
    $(function () {
        $('#from, #to').datetimepicker({
            autoclose: true,
            todayBtn: true,
            clearBtn: true,
            language: "zh-CN"
        });
    });
    var isLogin = <%= user==null?"0":"1"%>
    if(isLogin=="0"){
        window.location.href = contextPath+"/login";
    }
</script>
</body>
</html>

